package org.vector.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.vector.test.Test;
import org.vector.utils.BaseDao;

@SuppressWarnings("serial")
public class Last extends JFrame{
	BaseDao bd = new BaseDao();
	private JLabel l1,l2,l3,l4,l5,c1,c2,c3,c4,c5;
	private JButton b1,b2,b3,b4,b5,b6;
	
	public Last() {}
	public Last(int bankid) {
		into(bankid);
		setVisible(true);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	private void into(int bankid) {
		setSize(400,600);
		setLocationRelativeTo(null);
		setLayout(null);
		
		String sql = "select name,ccd,phone,money from bank where bankid = ?";
		ResultSet resultset = bd.executeQuery(sql, bankid);
		try {
			if(resultset.next()) {
				String name = resultset.getString("name");
				int ccd = resultset.getInt("ccd");
				int phone = resultset.getInt("phone");
				int money = resultset.getInt("money");
				
				c1 = new JLabel("账号");
				String bankid1 = Integer.toString(bankid);
				l1 = new JLabel(bankid1);
				c2 = new JLabel("用户名");
				l2 = new JLabel(name);
				c3 = new JLabel("银行卡号");
				String ccd2 = Integer.toString(ccd);
				l3 = new JLabel(ccd2);
				c4 = new JLabel("电话号");
				String phone1 = Integer.toString(phone);
				l4 = new JLabel(phone1);
				c5 = new JLabel("余额");
				String money1 = Integer.toString(money);
				l5 = new JLabel(money1);
				
				c1.setBounds(85, 50, 100, 75);
				l1.setBounds(140, 50,100, 75);
				c2.setBounds(85, 80, 100, 75);
				l2.setBounds(140, 80,100, 75);
				c3.setBounds(85, 110, 100, 75);
				l3.setBounds(140, 110, 100, 75);
				c4.setBounds(85, 140, 100, 75);
				l4.setBounds(140, 140, 100, 75);
				c5.setBounds(85, 170, 100, 75);
				l5.setBounds(140, 170,100, 75);
				
				add(c1);
				add(l1);
				add(c2);
				add(l2);
				add(c3);
				add(l3);
				add(c4);
				add(l4);
				add(c5);
				add(l5);
				
				b1 = new JButton("存款");
				b2 = new JButton("取款");
				b3 = new JButton("转账");
				b4 = new JButton("查看流水");
				b5 = new JButton("注销");
				b6 = new JButton("刷新");
				
				b1.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						new WindowSave(bankid);
					}
				});
				b2.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						new WindowDraw(bankid);
					}
				});
				b3.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						new WindowTransfer(bankid);
					}
				});
				b4.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						new DaytoDay(bankid);
					}
				});
				b5.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						Last.this.dispose();
						new Test();
					}
				});
				b6.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						Last.this.dispose();
						new Last(bankid);
					}
				});
				
				b1.setBounds(85, 250, 100, 75);
				b2.setBounds(200, 250, 100, 75);
				b3.setBounds(85, 350, 100, 75);
				b4.setBounds(200, 350, 100, 75);
				b5.setBounds(85, 450, 100, 75);
				b6.setBounds(200, 450,100, 75);
				
				add(b1);
				add(b2);
				add(b3);
				add(b4);
				add(b5);
				add(b6);
				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
//	public static void main(String[] args) {
//		new Last(1822);
//	}
}
